package com.igeekhome.microserviceprovideruser7001.controller;

import com.igeekhome.microservice.pojo.User;
import com.igeekhome.microserviceprovideruser7001.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微服务中的每个服务都需要向外部暴露HTTP API接口
 * @author yadonghe
 * @date 2020-02-21 10:33
 *
 * 服务提供者：
 * http://localhost:7001/user/get/1
 * */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/get/{id}")
    public User get(@PathVariable Long id) {

        //int i = 10/0;

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 调用service根据id查询用户信息
        //return new User(id, "张三", "admin", 22, new BigDecimal(8000));
        return userMapper.selectById(id);
    }

}
